﻿// =================================================================== 
// 数据实体层(GDIT.Model)实体映射
//====================================================================
// 文件：Mtb_Files.cs
// 项目名称：学院网站
// 创建时间：2012-08-08
// 负责人：ChenZhiGang
// 引用DevExpress.Xpo程序集
// 程序集介绍：文件实体类
// ===================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.Xpo;

namespace GDIT.Model
{
    public class Mtb_Files : PersistentClass
    {
            public Mtb_Files()
            : base()
        {
            this.Modified = false;
        }

            public Mtb_Files(Session theSession)
            : base(theSession)
        {
            this.Modified = false;
        }

        /// <summary>
        /// 文件所属的公告文章
        /// </summary>
        [Association("BulletinArticleFiles")]
         public Mtb_BulletinArticle BulletinArticle;

        /// <summary>
        /// 文件所属的校园资讯文章
        /// </summary>
        [Association("CollegeInformationArticleFiles")]
        public Mtb_CollegeInformationArticle CollegeInformationArticle;

        private string _fileName = string.Empty;
        /// <summary>
        /// 文件名称
        /// </summary>
        [DbType("varchar(256)")]
        public string FileName
        {
            get { return _fileName; }
            set
            {
                if (_fileName != value)
                {
                    _fileName = value;
                    if (!IsLoading) { this.Modified = true; }
                }
            }
        }

        private string _filePath = string.Empty;
        /// <summary>
        /// 文件内容
        /// </summary>
        [DbType("varchar(256)")]
        public string Contents
        {
            get { return _filePath; }
            set
            {
                if (_filePath != value)
                {
                    _filePath = value;
                    if (!IsLoading) { this.Modified = true; }
                }
            }
        }

        private DateTime _publishDate = DateTime.Now;
        /// <summary>
        /// 公告发布时间
        /// </summary>
        [DbType("datetime")]
        public DateTime PublishDate
        {
            get { return _publishDate; }
            set
            {
                if (_publishDate != value)
                {
                    _publishDate = value;
                    if (!IsLoading) { this.Modified = true; }
                }
            }
        }

        /// <summary>
        /// 防止编辑后马上保存
        /// </summary>
        protected override void EndEdit()
        {
            return;
        }

        /// <summary>
        /// 检验数据
        /// </summary>
        /// <returns></returns>
        public override string GetDataError()
        {
            if (this._filePath.Trim().Length == 0) { return string.Format("文件路径不能为空"); }
            if (this._fileName.Trim().Length == 0) { return string.Format("文件名称不能为空"); }
            return "";
        }
    }
}
